package repository;


import java.util.*;
import dto.*;
import java.sql.*;


public class OrderItemRepository 
{
      private DataBase db=null; 
      private PreparedStatement sqlCreate;
      
      public OrderItemRepository()
      {
       try
       {
           db=new DataBase();
       }
       catch(Exception e){}
      }
      
       public boolean Create(OrderItem newOrderItem)
      {
          try
          {
              sqlCreate=db.connection.prepareStatement("INSERT INTO OrderItems (productId, orderId) VALUES (?,?)");
              sqlCreate.setInt(1, newOrderItem.productId);
              sqlCreate.setInt(2, newOrderItem.orderId);
              int result=sqlCreate.executeUpdate();
              if (result==0)
              {
               db.connection.rollback();
               return false;
              }
              return true;
           }
          catch (Exception e)
          {
              return false;
          }
       }
}
